package dao;

import Utils.PageUitls;
import bean.Student;

import java.lang.annotation.Target;
import java.util.List;

public class StudentDao extends BaseDao<Student> {
    public int addStudent(Student student){
        String sql="INSERT INTO student(sname,sex,age,degree,pic,mark)VALUES(?,?,?,?,?,?)";
        return myupdate(sql,student.getSname(),student.getSex(),student.getAge(),student.getDegree(),
                student.getPic(),student.getMark());
    }
    public List<Student> findAllStudent(PageUitls pu){
        String sql="SELECT * FROM student limit ?,?";
        return myselesct_multi(sql,Student.class,pu.getStartIndex(),pu.getPageSize() );
    }
    public Student findStudentBySid(int sid){
        String sql="SELECT * FROM student where sid=?";
        return myselect_one(sql, Student.class,sid);
    }
    public int updateStudent(Student student){
        String sql  = "update student set sname=?,sex=?,age=?,degree=?,pic=?,mark=? where sid = ?";
        return  myupdate(sql,student.getSname(),student.getSex(),student.getAge(),student.getDegree(),student.getPic(),student.getMark(),student.getSid());
    }
    public int deleteStudent(Student student){
        String sql="DELETE FROM student WHERE sid=?";
        return myupdate(sql,student.getSid());
    }

    public int getTotalCounnt(){
        String sql="select count(*) from student";
        String obj=myscale(sql).toString();
        return Integer.parseInt(obj);
    }
    public Student checkSname(String sname){
        String sql="SELECT * FROM student where sname=?";
        return myselect_one(sql,Student.class ,sname);
    }


}
